/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.seari.semodbus.client;

import com.seari.semodbus.bean.PLCDevice;
import com.seari.semodbus.utils.JedisPoolUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

/**
 *
 * @author Rainbow
 */
public class RedisService implements Runnable
{

    int[] results;
    PLCDevice device;
    public RedisService(int [] results,PLCDevice device)
    {
        this.results = results;
        this.device = device;
    }
    
    @Override
    public void run()
    {
        Jedis jedis = JedisPoolUtils.getJedis();
        Pipeline pipeline = jedis.pipelined();
        for(int i=0;i < results.length;i++)
        {
            //System.out.println("device.getIp()+\"at\"+device.getPort()+device.getSlaveID()+device.getAddress()+i");
            //System.out.println(results[i]);
            //jedis.set(device.getIp()+"at"+device.getPort()+device.getSlaveID()+device.getAddress()+i, results[i]+"");
            pipeline.set(device.getIp()+"at"+device.getPort()+device.getSlaveID()+device.getAddress()+i, results[i]+"");
            pipeline.set("v"+(device.getVirtualStartPos()+i), results[i]+"");
        }
        pipeline.sync();
        jedis.disconnect();
        jedis.close();
    }
    
}
